package com.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.constant.MessageConstant;
import com.pageResult.PageResult;
import com.pojo.Member;
import com.pojo.Order;
import com.query.QueryPageBean;
import com.result.Result;
import com.service.OrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;


@RestController
@RequestMapping("/order")
public class OrderController {


    @Reference
    private OrderService orderService;


    //根据id查询对应的会员信息
    @RequestMapping("/updateStatus")
    public Result updateStatus(Integer id){
        try {
            orderService.updateStatus(id);
            return new Result(true, MessageConstant.DELETE_ORDER_FAIL);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.DELETE_ORDER_SUCCESS);
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody Member member, Integer SetmealId,String OrderDateValue,Integer id) throws Exception {
        return orderService.update(member, SetmealId, OrderDateValue,id);
    }

    //添加
    @PostMapping("/add")
    public Result add(@RequestBody Member member, Integer[] SetmealId,String OrderDateValue) throws Exception {
        return orderService.add(member, SetmealId, OrderDateValue);
    }

    //根据id查询对应的会员信息
    @RequestMapping("/queryById")
    public Result queryById(@RequestBody Order order){
        try {
            Map<String, Object> map = orderService.queryById(order);
            return new Result(true, MessageConstant.EDIT_ORDER_SUCCESS,map);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.EDIT_ORDER_FAIL);
    }

    //查询检查组（分页+条件）
    @PostMapping("/queryPage")
    public Result queryPage(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult result = orderService.selectByQueryString(queryPageBean);
            return new Result(true, MessageConstant.QUERY_USER_SUCCESS,result);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.QUERY_USER_FAIL);
    }

}
